﻿Imports TBCC.UtilityMobile
Public Class DocViewSetForm

    Private Sub btnOK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOK.Click
        If IsValidated() = True Then
            If SetDocViewType() = True Then
                msg.Show("保存成功。")
                Me.Close()
            Else
                msg.ShowError("保存失败。")
            End If
        End If
    End Sub

    Private Sub btnExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExit.Click
        Me.Close()
    End Sub

    Private Function SetDocViewType() As Boolean
        Try
            KeyValuePairClass.SetValue(MainForm.pi.ProjectID, "DocViewValue", CStr(CInt(nudMinute.Value)))
            KeyValuePairClass.SetValue(MainForm.pi.ProjectID, "DocViewType", CStr(cboIntevalType.SelectedIndex + 1))
        Catch ex As Exception
            Return False
        End Try

        Return True
    End Function

    Private Function IsValidated() As Boolean

        If Me.nudMinute.Value <= 0 Then
            msg.ShowError("间隔数值不能为0。")
            Return False
        End If

        If Me.cboIntevalType.SelectedIndex < 0 Then
            msg.ShowError("间隔类型不能为空。")
            Return False
        End If

        Return True
    End Function

    Private Sub DocViewSetForm_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Me.CenterToParent()
        Dim docViewType As String = KeyValuePairClass.GetValue(MainForm.pi.ProjectID, "DocViewType")
        Dim docViewValue As String = KeyValuePairClass.GetValue(MainForm.pi.ProjectID, "DocViewValue")

        If docViewType.Length > 0 Then cboIntevalType.SelectedIndex = CInt(docViewType) - 1
        If docViewValue.Length > 0 Then nudMinute.Value = CInt(docViewValue)
    End Sub

    Private Sub cboIntevalType_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cboIntevalType.SelectedIndexChanged
        Select Case sender.SelectedIndex
            Case 0
                Me.nudMinute.Minimum = 10
                Me.nudMinute.Maximum = 60
                Me.nudMinute.Increment = 10
                Me.nudMinute.Value = 10
            Case 1
                Me.nudMinute.Minimum = 0
                Me.nudMinute.Maximum = 60
                Me.nudMinute.Increment = 1
                Me.nudMinute.Value = 1
            Case 2
                Me.nudMinute.Minimum = 0
                Me.nudMinute.Maximum = 60
                Me.nudMinute.Increment = 1
                Me.nudMinute.Value = 1
        End Select
    End Sub

    Private Sub nudMinute_ValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles nudMinute.ValueChanged
        Select Case cboIntevalType.SelectedIndex
            Case 0
                If sender.Value Mod 10 <> 0 Then
                    sender.Value = (sender.Value \ 10) * 10
                End If
                If sender.Value = sender.Maximum Then
                    Me.cboIntevalType.SelectedIndex = 1
                End If
            Case 1
                If sender.Value = sender.Minimum Then
                    Me.cboIntevalType.SelectedIndex = 0
                    sender.Value = 50
                End If
                If sender.Value = sender.Maximum Then
                    Me.cboIntevalType.SelectedIndex = 2
                End If
            Case 2
                If sender.Value = sender.Minimum Then
                    Me.cboIntevalType.SelectedIndex = 1
                    sender.Value = 59
                End If
        End Select
    End Sub
End Class